"""
基础赋值,继承Operators/OperationOperators/OperatorIVQROF.py中的Operator_IVQ_ROFS算子借此融入系统
"""
import numpy as np
from Utilities.AutoGetOperator.selectPackage import get_func

Operator_IVQ_ROFS=get_func(r'Operators/OperationOperators/OperatorIVQROF.py','Operator_IVQ_ROFS')

class Operator(Operator_IVQ_ROFS):
    def __init__(self,U_list=[],heavy_weight_list=[],P_list=[],rate_list =[]):
        """
        function:初始化数据
        :param data_list:6个月的数据集
        :param U_list:诱导向量
        :param weight_list:加权向量
        :param heavy_weight_list:重加权向量
        :param P_list:概率向量
        :param rate_list:权重向量和概率向量的比率
        """
        super(Operator,self).__init__()

        if (len(U_list)):
            self.U_list = U_list
        else:
            # self.U_list = [5,15,10,20,30,25]
            self.U_list = [5*(1+i) for i in range(len(self.data_list))]



        if (len(heavy_weight_list)):
            self.heavy_weight_list = heavy_weight_list
        else:
            # self.heavy_weight_list = [0.10,0.10,0.20,0.20,0.20,0.30]
            temp=list(np.random.randint(10,size=len(self.data_list)))
            self.heavy_weight_list=[i/sum(temp) for i in temp]


        if (len(P_list)):
            self.P_list = P_list
        else:
            # self.P_list = [0.15,0.15,0.15,0.15,0.20,0.20]
            temp = list(np.random.randint(10, size=len(self.data_list)))
            self.heavy_weight_list = [i / sum(temp) for i in temp]

        if (len(rate_list)):
            self.rate_list = rate_list
        else:
            self.rate_list = [0.6,0.4]

    def asc(self,a):
        """
        function:升序排列
        :param a: 一个数据集
        :return:
        """
        for i in range(len(a)):
            for j in range(i+1,len(a)):
                if a[j] < a[i]:
                    temp = a[i]
                    a[i] = a[j]
                    a[j] = temp
        return a

    def des(self,a):
        """
        function:降序排列
        :param a: 一个数据集
        :return:
        """
        for i in range(len(a)):
            for j in range(i+1,len(a)):
                if a[j] > a[i]:
                    temp = a[i]
                    a[i] = a[j]
                    a[j] = temp
        return a

    def U_asc(self,a):
        """
         function:对U进行升序排列，并获得其对应索引位置
        :param a: 一个数据集
        :return: 索引数组
        """
        # 对索引元组初始化
        u_index = [i for i in range(len(a))]
        for i in range(len(a)):
            for j in range(i+1,len(a)):
                if a[j] < a[i]:
                    temp = u_index[i]
                    u_index[i] = u_index[j]
                    u_index[j] = temp

        return u_index


